import itertools


class Generate(object):
    def __init__(self, len) -> None:
        self.__len = len

    def generate(self):

        pwdGenerator = (''.join(_) for _ in itertools.product(
            '01234567890123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ',
            repeat=self.__len))
        passwords = ''
        i = 0
        for pwd in pwdGenerator:
            passwords += f'{pwd}\n'
            # 每一百个写入一次文件
            if i % 100 == 0:
                with open(f'{self.__len}.pwd', 'a') as f:
                    f.write(passwords)
                passwords = ''
            i += 1
        # 如果还有剩，将他们写入文件
        if not (i % 100 == 0):
            with open(f'{len}.pwd', 'a') as f:
                f.write(passwords)


if __name__ == '__main__':
    g = Generate(8)
    g.generate()
